/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package models;
import java.util.*;
import javax.persistence.*;
import play.data.format.*;
import play.data.validation.*; 

import play.db.jpa.*;
@Entity
public class Usuario {
@Id
@Constraints.Required
public String login;
@Constraints.Required
public String password;
@Constraints.Required
public String nombreCompleto;
@Transient
public Boolean esAdministrador;
public Integer administrador;
public Integer estado;
@Formats.DateTime(pattern="yyyy-MM-dd")
public Date fechaCreacion;
public static Usuario findById(String login) {
return JPA.em().find(Usuario.class, login);
}




public void update(String login) {
this.login = login;
JPA.em().merge(this);
}
public void save() {
System.out.println("Grabando nuevo usuario...");
this.estado = new Integer(1);
this.fechaCreacion =new java.util.Date();
JPA.em().persist(this);
}
public void delete() {
JPA.em().remove(this);
} 


   public static Page page(){
        List<Usuario> users =  JPA.em().createQuery("from Usuario").getResultList();
        return new Page(users);
    }
       
   
    public static class Page{
        private final List<Usuario> list;
        
        public Page(List<Usuario> data){
            this.list = data;
        }    
        public  List<Usuario> getList(){
            return list;
            
        }
                
    }

}